package com.teamwings.modules.oss.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.util.Date;

/**
 * oss文件类 (这里核心是多态关联，通过两个字段来指向文件和表单实例的关系)
 * 多态关联理解：https://blog.csdn.net/qwbtc/article/details/52035603
 */
@Data
@TableName("FORM_TABLE_OSS_FILE")
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class OssFile implements Serializable {

	private static final long serialVersionUID = 1L;

	// 文件id
	@TableId(value = "ID")
	private String id;

	// 多态关联对应的表单 formId
	@TableField(value = "FORM_ID")
	private String formId;

	// 多态关联的表单的id
	@TableField(value = "TABLE_ID")
	private String tableId;

	// 记录表名称，这里是一个冗余字段, 可以通过formId找到tableName
	@TableField(value = "TABLE_NAME")
	private String tableName;

	// 文件名
	@TableField(value = "FILE_NAME")
	private String fileName;

	// 文件名路径
	@TableField(value = "FILE_PATH")
	private String filePath;

	// 文件后缀
	@TableField(value = "FILE_SUFFIX")
	private String fileSuffix;

	// 文件类型
	@TableField(value = "FILE_TYPE")
	private String fileType;

	// 文件url
	@TableField(value = "URL")
	private String url;

	@TableField(value = "CREATE_BY", fill = FieldFill.INSERT)
	protected String createBy;

	@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@TableField(value = "CREATE_TIME", fill = FieldFill.INSERT)
	protected Date createTime;

	@TableField(value = "UPDATE_BY", fill = FieldFill.INSERT_UPDATE)
	protected String updateBy;

	@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@TableField(value = "UPDATE_TIME", fill = FieldFill.INSERT_UPDATE)
	protected Date updateTime;

	@TableField(value = "UPLOAD_LIST")
	private String uploadList;

}
